import request from '@/utils/request'
import math from '@/utils/math'

// 收入记录列表
export function qryIncomeRecord(data) {
  return request({
    url: '/order_mobile/trade/qryIncomeRecord',
    method: 'post',
    data: data
  })
}
// 收入记录导出
export function exportMercIncome(data) {
  return request({
    url: '/statistics_admin/task/export_merc_income',
    method: 'post',
    data
  })
}
// 退款记录列表
export function qryRefundRecord(data) {
  return request({
    url: '/order_mobile/trade/qryRefundRecord',
    method: 'post',
    data: data
  })
}
// 退款记录 导出
export function exportMercRefund(data) {
  return request({
    url: '/statistics_admin/task/export_merc_refund',
    method: 'post',
    data: data
  })
}
// 支出记录列表
export function qryExpendRecord(data) {
  return request({
    url: '/order_mobile/trade/qryExpendRecord',
    method: 'post',
    data: data
  })
}
// 支出记录导出
export function exportMercExpend(data) {
  return request({
    url: '/statistics_admin/task/export_merc_expend',
    method: 'post',
    data: data
  })
}
// 交易概览数据源
export function qryDaySumTrade(data) {
  return request({
    url: '/order_mobile/trade/qryDaySumTrade',
    method: 'post',
    data: data
  })
}
// 根据订单号orderNo查询退款记录
export function qryRefundListByOrderNo(orderNo) {
  return request({
    url: '/order_mobile/trade/qryRefundListByOrderNo/' + orderNo,
    method: 'post'
  })
}
// 商城订单取消
export function mallOrderCancel(data) {
  return request({
    url: '/mall/admin/order/cancel',
    method: 'post',
    data: data
  })
}
// 商城订单退款
export function mallOrderRefund(data) {
  return request({
    url: '/mall/admin/order/refund',
    method: 'post',
    data
  })
}
// 码牌、收款类型  退款
export function tradeRefund(data) {
  return request({
    url: '/order_mobile/trade/refund',
    method: 'post',
    data
  })
}
// 修改订单状态
export function changeOrderStatus(data) {
  return request({
    url: '/booking_admin/booking_manage/change_order_status',
    method: 'post',
    data
  })
}
// 校验登录密码
export function chkLoginPwd(data) {
  return request({
    url: '/business_admin/user/chkLoginPwd',
    method: 'post',
    data
  })
}
// 查询第三方刷卡交易订单列表
export function thirdList(data) {
  return request({
    url: '/memberAdmin/third/list',
    method: 'post',
    data
  })
}
// 查询导出交易订单列表
export function export_third_push_order(data) {
  return request({
    url: '/statistics_admin/task/export_third_push_order',
    method: 'post',
    data
  })
}

/**
 * 汇总订单退款, 不同业务类型存在不同退款接口，需要区分调用
 * type     订单业务类型   会员充值：2,会员开卡：34,商城：5,点餐：6,预订：7,赠送会员：9,会员续费：10,码牌支付：14,收款：15,插件返佣：16
 * status   订单状态
 */
export function orderRefund(baseData) {
  console.log('orderRefund', this)
  const { status, type, orderNo, remark, money, pwd, generalFlag } = baseData
  let data = { generalFlag, orderNo }
  let url = ''
  if (type == 5) {
    // 商城类型订单
    if (status == 4 || status == 2) {
      // 订单状态 已支付 或者 已完成
      url = '/mall/admin/order/refund'
      data = {
        ...data,
        reason: remark,
        refundFee: math.mul(money, 100),
        depositRefundFee: ''
      }
    } else {
      url = '/mall/admin/order/cancel'
      data = {
        ...data,
        reason: remark
      }
    }
  } else if (type == 6) {
    // 点餐类型
    url = '/wcanyin_admin/manage/refundOrder'
    data = {
      ...data,
      reason: remark,
      refundPwd: pwd
    }
  } else if (type == 14 || type == 15) {
    // 码牌 、 收款类型退款
    url = '/order_mobile/trade/refund'
    data = {
      ...data,
      type,
      reason: remark,
      refundFee: math.mul(money, 100)
    }
  } else {
    url = '/booking_admin/booking_manage/change_order_status'
    data = {
      ...data,
      status: 0,
      refundFee: math.mul(money, 100),
      cancelReason: remark
    }
  }
  console.log({ url, data, method: 'post' })
  return request({
    url, data,
    method: 'post'
  })
}
